package com.itheima.ssm.controller;

import com.itheima.ssm.domain.Pemission;
import com.itheima.ssm.service.IPermessionService;
import org.apache.ibatis.annotations.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

@Controller
@RequestMapping("/permession")
public class PermessionController {

    @Autowired
    private IPermessionService iPermessionService;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception{
        ModelAndView mv = new ModelAndView();
        List<Pemission> pemissionList = iPermessionService.findAll();
        mv.addObject("permessionList",pemissionList);
        mv.setViewName("permession-list");
        return mv;
    }

    @RequestMapping("/save.do")
    public String save(Pemission pemission) throws Exception {
        iPermessionService.save(pemission);
        return "redirect:findAll.do";
    }

    @RequestMapping("/finById.do")
    public ModelAndView findById(int permessionId) throws Exception {
        ModelAndView mv = new ModelAndView();
        Pemission pemission = iPermessionService.findById(permessionId);
        mv.addObject("pemission",pemission);
        mv.setViewName("permission-show");
        return mv;
    }

}
